(function($) {
	var ToggleButton = (function() {
		//私有方法，外面将访问不到
		var _bind = function() {

		}
		var _getNum = function() {

		}
		function ToggleButton(element, options) {
			//var this = new Object();//系统自己干的，构造函数的特点
			this.settings = $.extend(true, $.fn.ToggleButton.defaults, options || {});
			this.element = element; //当前对象
			//console.log(this.element);
			//console.log(typeof this.element);
			this.init();
		}
		ToggleButton.prototype = {
				init: function() {
					var me = this;
					me.showToggle = me.settings.showToggle;
					me.slideSpeed = me.settings.slideSpeed;
					me.initToggleOpen();
					me.initToggleClick();
				},
				initToggleOpen: function() {
					var me = this;
					var settings = me.settings;
					if(settings.showToggle === true) {
						$("#ToggleButton").show();
					} else {
						$("#ToggleButton").hide();
					}
				},
				//选择开始时候的样式
				initStartStyle: function() {

				},
				//初始化toggle的点击移动
				initToggleClick: function() {
					var me = this;
					var settings = me.settings;
					//console.log(me); //ToggleButton这个对象
					//console.log(me.element); //调用对象的那个dom
					var now = me.element;
					$("#ToggleButton").click(function() {
						$(this).toggleClass('off-color');
						$(this).toggleClass('on-color');
						var $btnW = $(this).innerWidth();
						var $needW = $btnW / 2;
						if($(this).hasClass('on-color')) {
							$(".toggle-line").animate({
								'left': $needW,
							}, settings.slideSpeed);
							$('.toggle-line').prop('toggleBool', false);
						} else {
							$(".toggle-line").animate({
								'left': 3,
							}, settings.slideSpeed);
							$('.toggle-line').prop('toggleBool', true);
						}
					});
				}
			}
			//返回构造函数
		return ToggleButton;
	})();

	jQuery.prototype.ToggleButton = function(options) {
		return this.each(function() {
			var me = $(this),
				instance = me.data('ToggleButton'); //data缓存器
			if(!instance) {
				me.data('ToggleButton', (instance = new ToggleButton(me, options)))
			}
			if($.type(options) === 'string') {
				return instance[options]();
			}
		})
	};
	jQuery.prototype.ToggleButton.defaults = {
		slideSpeed: 300,
		showToggle: true
	};
})(jQuery);